<%@ page contentType="text/html;charset=UTF-8" import="java.util.*,com.nail.zhaogr.model.*"%>
<%@ include file="/commons/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<%@ include file="/commons/meta.jsp" %>
	<script src="${ctx}/scripts/bar.js" type="text/javascript"></script>
	
	
	
	<base target="_self" />
	
	<style>
	.black_overlay{ 
            display: none; 
            position: absolute!important; 
            top: 0px; 
            left: 0px; 
            width:100%; 
            height:100%!important 
            background-color:#eee;
            z-index:1001; 
            -moz-opacity: 0.8; 
            opacity:.80; 
            filter: alpha(opacity=80); 
        } 
        .white_content { 
            display: none; 
            position: absolute; 
            top: 25%; 
            left: 25%; 
            width: 500px; 
            height: 270px; 
            padding: 16px; 
            border: 16px solid orange; 
            background-color: white; 
            z-index:1002; 
            overflow: auto; 
        }
	</style>
</head>
<%
  Members members=new Members();
  String loginName ="";
  if(session.getAttribute("memberInfo")!=null){
  	members = (Members)session.getAttribute("memberInfo");
  	loginName = members.getLoginName();
  }

  %>
<body style="height:100%">
<s:form id="submitForm" action="/PublishInfo/save.do" method="post"  theme="simple">
<div id="fade" class="black_overlay">&nbsp;</div> 
<div class="twidth">
	<div class="topBar">
		<div class="twidth">
			<div id="currentCity">
				<font>成都</font><a href="#">切换城市</a> <a style="margin-left:10px;" href="${ctx}/">首页</a> → <a href="#">成都找工人网</a> → <a href="#">装修工人</a>
			</div>
			<div id="topUser">
				<a href="${ctx}/PublishInfo/create.do" class="postMsg">免费发布信息</a>
				<a id="memberLink" href="${ctx}/MemberCenter/index.do">会员中心</a>
				<a id="exitLink" href="${ctx}/Login/exit.do">退出</a>
				<a id="loginLink" href="${ctx}/Login/indexLogin.do">我要登录</a>
				<a id="registerLink" href="${ctx}/Register/indexMembers.do">我要注册</a>
				<a href="javascript:void(0);" onClick="window.external.AddFavorite(document.location.href,document.title)">加入收藏</a>
				<a href="#">设为首页</a>
			</div>
		</div>
	</div>
	
  	<div class="twidth" style="margin-top:8px;">

	<div style="width:710px;float:left">
		<div class="mframe mR">
			<div class="tl"></div>
			<div class="tr"></div>
			<div class="tm">
				<div class="tit"><span class="tt"><s:property value="%{model.category.categoryName}" />-${cityThree}</span></div><div class="titr"></div> 
				<s:hidden id="publishInfoId" name="publishInfoId"></s:hidden>
			</div>
			<div class="wrapper">
				<div class="ml"></div>
				<div class="mr"></div>
				<div class="mm" style="padding:0 15px">
					<br/>
					<div align="center"><h1 class="aTitle"><s:property value="%{model.category.categoryName}" />  -  <s:property value="%{model.name}" /></h1></div>
					<table width="100%" align="center" bgcolor="#e0e0e0" cellspacing="1" cellpadding="5">
						<tr class="tdbg">
							<td width="60%" colspan="2"><strong>姓名：</strong>${name}</td>
							<td width="40%"  rowspan="16" align="center"></td>
						</tr>
						<tr class="tdbg-dark">
							<td>
							<strong>性别：</strong></td>
							<td>${gender}</td>
						</tr>
			
						<tr class="tdbg">
							<td>
							<strong>住址：</strong></td>
							<td>${cityTwo}-${cityThree}</td>
						</tr>
						
						<tr class="tdbg-dark">
							<td>
							<strong>服务区域：</strong></td>
							<td>${serviceArea}</td>
						</tr>
						
						<tr class="tdbg">
							<td><strong>从事本工作时间：</strong> </td>
							<td>${workAge}</td>
						</tr>
						<tr class="tdbg-dark">
							<td><strong>年龄：</strong></td>
							<td>${age}</td>
						</tr>
						<tr class="tdbg">
							<td><strong>联系电话：</strong> </td>
							<td>
								<s:if test="%{hasTrade==1}">
									<span style="color:red;font-size: 16px;font-weight: bold">${phone}</span>
								</s:if>
								<s:else>
								<input type="button" onclick="javascript:getPhone();" title="查看电话号码将消费一个积分" style="color:red" value="查看联系电话" />
								
								<div id="lightDiv" class="white_content">
								<a href = "javascript:void(0)" style="float:right;padding:0;margin:0;" onclick = "document.getElementById('lightDiv').style.display='none';document.getElementById('fade').style.display='none'">关闭</a>
									<br />
										<p style=";margin-left: 20px">联系电话：<span id="phone" style="color:red;font-size: 16px;font-weight: bold"></span></p> 
										<label id="autoRedirect" style="display:none"></label>									
											<label style="margin:0px 0px 20px 20px;">我要评价他的服务态度</label>
											<br />
											<div style="padding-left: 10px;margin: 10px 0px 0px 20px;">
											<input type="radio" id="attitude6" name="attitude" value="3"  onclick="doSetAttitude(3)"/><label for="attitude6" onclick="doSetAttitude(3)">态度优秀</label>&nbsp;&nbsp;
											<input type="radio" id="attitude4" name="attitude" value="2"  onclick="doSetAttitude(2)"/><label for="attitude4" onclick="doSetAttitude(2)">态度良好</label>&nbsp;&nbsp;
											<input type="radio" id="attitude2" name="attitude" value="1"  onclick="doSetAttitude(1)"/><label for="attitude2" onclick="doSetAttitude(1)">态度一般</label>&nbsp;&nbsp;
											<input type="radio" id="attitude0" name="attitude" value="-1" onclick="doSetAttitude(-1)"  /><label for="attitude0" onclick="doSetAttitude(-1)">态度较差</label>&nbsp;&nbsp;
										   	&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" onclick="doCommentAttitude()" value="提交评论" />
										   </div>
										   <div id = "commentsReturn" style="height:20px;margin-top: 20px;text-align: center;color: red;font-weight: bold"></div>
										   <div id = "invite" style="margin-top: 10px;text-align: center;color: red;font-weight: bold">服务态度不错，<input type="button" value="我要邀请 ${name}" onClick="doInvite()"></div>
										   <div id = "inviteReturn" style="height:20px;margin-top: 10px;text-align: center;color: red;font-weight: bold"></div>
											<div style="margin-top: 40px;">
												您当前拥有 ${session.memberInfo.points}个会员积分&nbsp; &nbsp;    您可以通过评论工人，发布工人信息来增加会员积分
											</div>
								</div> 
								</s:else>
							</td>
						</tr>
						<tr class="tdbg-dark">
							<td>
							<strong>信用等级：</strong></td>
							<td>***</td>
						</tr>
						
					</table>
					<br/>
					
					<div id="content">
					【基本介绍】<br />&nbsp; &nbsp; &nbsp; &nbsp;${profile }
					<br /><br />
					</div>
					<div style="text-align:right;clear:both">
						<a href="javascript:doFavorite()"  class="fav">收藏</a> <span class="gray">(${favoriteCount==null?0:favoriteCount})
						<a href="javascript:doCommend()" onclick="" class="mail">推荐</a><span class="gray">(${commendCount==null?0:commendCount})						
					</div>
					<div class="nearNews">
						<div class="prevNews"></div>
						<div class="nextNews"></div>
					</div>
				</div>
			</div>
			<div class="bl"></div>
			<div class="br"></div>
			<div class="bm"></div>
		</div>
	
		<div class="mframe mR">
			<div class="tl"></div>
			<div class="tr"></div>
			<div class="tm">
				<span class="tt">服务态度评价</span>
			</div>
			<div class="wrapper">
			<div class="ml"></div>
			<div class="mr"></div>
			<div class="mm" id="attitude5555">
				<ul id="attitude">
				</ul>
			</div>
			</div>
			<div class="bl"></div>
			<div class="br"></div>
			<div class="bm"></div>
		</div>

		<div class="mframe mR">
			<div class="tl"></div>
			<div class="tr"></div>
			<div class="tm">
				<span class="tt">服务质量评价</span>
			</div>
			<div class="wrapper">
			<div class="ml"></div>
			<div class="mr"></div>
			<div class="mm">
				<ul id="quality">
				</ul>
			</div>
			</div>
			<div class="bl"></div>
			<div class="br"></div>
			<div class="bm"></div>
		</div>


		<div class="mframe mR">
			<div class="tl"></div>
			<div class="tr"></div>
			<div class="tm">
				<span class="tt">评论</span>
				 	　　<a href="${ctx}/Comments/list.do?publishInfoId=${publishInfoId}" target="_blank">查看全部评论</a> <span class="gray">(${commentCount==null?0:commentCount})</span>
			</div>
			<div class="wrapper">
			<div class="ml"></div>
			<div class="mr"></div>
			<div class="mm">
				<s:iterator value="model.commentss" status="state" >
					<div class="commentDiv">
					<li class="comments">
					服务态度评价：<s:if test="%{attitude==3}">态度出色</s:if>
					<s:elseif test="%{attitude==2}">态度不错</s:elseif>
					<s:elseif test="%{attitude==1}">态度一般</s:elseif>
					<s:elseif test="%{attitude==-1}">态度较差</s:elseif>
					
					</li>
					<li class="comments">服务质量评价：<s:if test="%{quality==3}">手艺很好</s:if>
					<s:elseif test="%{quality==2}">手艺良好</s:elseif>
					<s:elseif test="%{quality==1}">手艺一般</s:elseif>
					<s:elseif test="%{quality==-1}">手艺很差</s:elseif></li>
					<li class="commentContents"><span>&nbsp;&nbsp;&nbsp;一句话评价：</span>${contents}</li>
					<li class="commentUser">
					<font style="color:#bbb">评论人：</font><span>${members.loginName}</span> 
					&nbsp;&nbsp;&nbsp;<span>${commentDateString}</span> </li> 
					</div>
				</s:iterator>
			</div>
			</div>
			<div class="bl"></div>
			<div class="br"></div>
			<div class="bm"></div>
		</div>
	</div>
  	<%@include file="/commons/star.html" %>
	</div>
	<jsp:include page="/commons/bottom.html"  flush="true"></jsp:include>
	</div>
	</s:form>
<script>
	
	var sec = 5;
	var wait = sec * 1000;
	var attitudeValue;
	var hasComment=false;
	function TimeUpdate(num) {
	 if(num != sec) {
	  var pntNum = (wait / 1000) - num;
	  document.getElementById("autoRedirect").innerText = "等待[" + pntNum + "]秒，系统自动跳转到登录页面";
	 }
	}
	
	function TimeOk() {
	 window.location= "${ctx}/Login/indexLogin.do";
	}
	
	
	/*new Validation(document.forms[0],{onSubmit:true,onFormValidate : function(result,form) {
		var finalResult = result;
		//在这里添加自定义验证
		//disableSubmit(finalResult,'submitButton');
		if(finalResult)
		{ 
			doComment();
			//return finalResult;
		}else{
			return finalResult;
		}
		
	}});*/
	
	function doComment()
	{
		var json ={};
		json.publishInfoId = document.getElementById("publishInfoId").value;
		json.contents =  document.getElementById("contents").value;
		$.ajax(
			{url:"${ctx}/Comments/save.do",
			data:json,
			success:function responseData(jsonData){
				hasComment = true;
				if(jsonData=='1'){
					alert("请先登录再发表评论");
				}else if(jsonData=='2'){
					alert("您所提交的信息中有不合法，不文明的词语，请修改后再发布");
				}else if(jsonData=='3'){
					alert("不可评价自己发布的信息");
				}else
				{
					document.getElementById("commentsList").innerHTML += jsonData;
				}
			}
			}
		);
	}
	
	function doCommentAttitude(){
		var json ={};
		json.publishInfoId = document.getElementById("publishInfoId").value;
		json.attitude =  attitudeValue;
		json.memberId=  ${memberId};
		json.flag = 1;
		
		$.ajax(
			{url:"${ctx}/Comments/commentAttitude.do",
			data:json,
			success:function responseData(jsonData){
			hasComment = true;
				if(jsonData=='1'){
					alert("请先登录再发表评论");
				}else if(jsonData=='3'){
					alert("不可评价自己发布的信息");
				}else
				{
					document.getElementById("commentsReturn").innerHTML = jsonData;
				}
			}
			}
		);
	}
	
	function doInvite(){
		var json ={};
		json.publishInfoId = document.getElementById("publishInfoId").value;
		json.attitude = 3;
		json.memberId=  ${memberId};
		if(hasComment){
			json.flag=3;
		}else{
			json.flag = 2;
		}
		$.ajax(
			{url:"${ctx}/Comments/commentAttitude.do",
			data:json,
			success:function responseData(jsonData){
				if(jsonData=='1'){
					alert("请先登录再邀请工人");
				}else if(jsonData=='3'){
					alert("请不要对自己发布的信息进行评价和其他操作，我们会使您的行为为恶意炒作");
				}else
				{
					document.getElementById("commentsReturn").innerHTML = jsonData;
				}
			}
			}
		);
	}
	
	function doSetAttitude(obj){
		attitudeValue = obj;
	}
	
	function getPhone(){
		if(confirm("查看工人联系电话将消费一个积分，请确定是否继续")){
			document.getElementById("lightDiv").style.display='block';
			document.getElementById("fade").style.display='block';
			var json ={};
			json.publishInfoId = document.getElementById("publishInfoId").value;
			$.ajax(
				{url:"${ctx}/PublishInfo/showPhone.do",
				data:json,
				success:function responseData(jsonData){
					if(jsonData=='0'){
						alert("您的积分不够，请通过发布工人信息，评价工人获得积分");
					}else if(jsonData=='-1'){
						document.getElementById("phone").innerHTML += "您所操作的是会员功能,请先登录再查看电话号码";
						document.getElementById("autoRedirect").style.display ="";
						for(var i = 0; i <= sec; i++) {
						 window.setTimeout("TimeUpdate(" + i + ")", i * 1000);
						}
						window.setTimeout("TimeOk()", wait);
					}
					else
					{
						document.getElementById("phone").innerHTML = jsonData;
					}
				}
				}
			);
		}else{
			return false;
		}
	}
	function doFavorite(){
		var json ={};
		json.publishInfoId = document.getElementById("publishInfoId").value;
		json.memberId = ${session.memberInfo.memberId}+"";
		$.ajax(
			{url:"${ctx}/PublishInfo/favorite.do",
			data:json,
			success:function responseData(jsonData){
				alert(jsonData);
			}
			}
		);
	}
	
	function doCommend(){
		var json ={};
		json.publishInfoId = document.getElementById("publishInfoId").value;
		json.memberId = ${session.memberInfo.memberId}+"";
		$.ajax(
			{url:"${ctx}/PublishInfo/commend.do",
			data:json,
			success:function responseData(jsonData){
				alert(jsonData);
			}
			}
		);
	}
	
  	if('<%=loginName%>'!=''){
  		document.getElementById("memberLink").style.display='';
  		document.getElementById("exitLink").style.display='';
  		document.getElementById("loginLink").style.display='none';
  		document.getElementById("registerLink").style.display='none';
  	}else{
  		document.getElementById("memberLink").style.display='none';
  		document.getElementById("exitLink").style.display='none';
  		document.getElementById("loginLink").style.display='';
  		document.getElementById("registerLink").style.display='';
  	}
  	

	var attitudedata = [];
	attitudedata[0] = ['态度很好','${attitude4==null?0:attitude4}'];
	attitudedata[1] = ['态度良好','${attitude3==null?0:attitude3}'];
	attitudedata[2] = ['态度一般','${attitude2==null?0:attitude2}'];
	attitudedata[3] = ['态度很差','${attitude1==null?0:attitude1}'];
	
	var bar1 = new bar();
	bar1.id = 'attitude';
	bar1.data = attitudedata;
	bar1.show();
	
	
	var qualitydata = [];
	qualitydata[0] = ['质量很好','${quality4==null?0:quality4}'];
	qualitydata[1] = ['质量良好','${quality3==null?0:quality3}'];
	qualitydata[2] = ['质量一般','${quality2==null?0:quality2}'];
	qualitydata[3] = ['质量很差','${quality1==null?0:quality1}'];
	
	var bar2 = new bar();
	bar2.id = 'quality';
	bar2.data = qualitydata;
	bar2.show();
	</script>
</body>
</html>